
ARCH := $(shell uname -p)

ifeq ($(ARCH), i386)
LIBPREFIX = x86
else
LIBPREFIX = arm
endif

CC = ${COMPILER_PREFIX}gcc
CFLAGS = -c -Wall -I../res/raylib/include
LDFLAGS = -lpthread -L../res/raylib/lib/mac/$(LIBPREFIX) -lraylib -lfreeimage -lm
#LDFLAGS = -lpthread `pkg-config --libs raylib`
RAYLIB = -framework OpenGL -framework Cocoa -framework IOKit
LDFLAGS += $(RAYLIB)

SOURCES = pub_lib.c geometric_algo.c image.c\
	multi_image_skelton.c basic.c gtransform.c\
	intensity.c intensity_algo.c \
	spatial_filter.c spatial_filter_algo.c fuzzy_algo.c \
	filter_freq_domain.c fft.c \
	restoration.c restoration_algo.c fft_util.c \
	color_image.c \
	morphology.c morphology_algo.c morph_gray.c

OBJECTS = $(SOURCES:.c=.o)
PUBOBJS = pub_lib.o
TIFFOBJS = image.o intensity_algo.o spatial_filter_algo.o
FFTOBJS = fft.o fft_util.o restoration_algo.o

DEMO_OBJS = $(PUBOBJS) $(TIFFOBJS)
SMALL_OBJS = $(PUBOBJS) image.o

SAMPLE = sample
BASIC = basic
GTRANSFORM = gtransform

#ch3
INTENSITY =  intensity
SPATIAL_FILTER = spatial_filter

#ch4
FILTER_FREQ = freq_filter

#ch5
RESTORATION = restoration

#ch6
COLORIMAGE = colorimage

#ch9
MORPH = morphology
MORPH_GRAY = morph_gray

all: $(SOURCES) $(SAMPLE) $(BASIC) $(GTRANSFORM) \
	$(INTENSITY) $(SPATIAL_FILTER) $(FILTER_FREQ)\
	$(RESTORATION) $(COLORIMAGE) $(MORPH) $(MORPH_GRAY)

$(SAMPLE): multi_image_skelton.o $(PUBOBJS) $(TIFFOBJS)
	ARCH=$(ARCH)
	$(CC) multi_image_skelton.o $(PUBOBJS) $(TIFFOBJS) -o $@ $(LDFLAGS)

$(INTENSITY): intensity.o $(PUBOBJS) $(TIFFOBJS)
	$(CC) intensity.o $(PUBOBJS) $(TIFFOBJS) -o $@ $(LDFLAGS)

$(SPATIAL_FILTER): spatial_filter.o fuzzy_algo.o $(PUBOBJS) $(TIFFOBJS)
	$(CC) spatial_filter.o fuzzy_algo.o $(PUBOBJS) $(TIFFOBJS) -o $@ $(LDFLAGS)

$(FILTER_FREQ): filter_freq_domain.o $(FFTOBJS) $(PUBOBJS) $(TIFFOBJS)
	$(CC) filter_freq_domain.o $(FFTOBJS) $(PUBOBJS) $(TIFFOBJS) -o $@ $(LDFLAGS) -lfftw3f

$(RESTORATION): restoration.o $(FFTOBJS) $(PUBOBJS) $(TIFFOBJS)
	$(CC) restoration.o $(FFTOBJS) $(PUBOBJS) $(TIFFOBJS) -o $@ $(LDFLAGS) -lfftw3f

$(COLORIMAGE): color_image.o $(DEMO_OBJS)
	$(CC) color_image.o $(DEMO_OBJS) -o $@ $(LDFLAGS)

$(MORPH): morphology.o morphology_algo.o $(DEMO_OBJS)
	$(CC) morphology.o morphology_algo.o $(DEMO_OBJS) -o $@ $(LDFLAGS)

$(MORPH_GRAY): morph_gray.o morphology_algo.o $(DEMO_OBJS)
	$(CC) morph_gray.o morphology_algo.o $(DEMO_OBJS) -o $@ $(LDFLAGS)


##############################################################

$(BASIC): basic.o $(PUBOBJS)
	$(CC) basic.o $(PUBOBJS) -o $@ $(LDFLAGS)

$(GTRANSFORM): gtransform.o geometric_algo.o $(PUBOBJS)
	$(CC) gtransform.o geometric_algo.o $(PUBOBJS) -o $@ $(LDFLAGS)

.c.o:
	$(CC) $(CFLAGS) $< -o $@

clean:
	rm -f *.o $(SAMPLE) $(BASIC) $(GTRANSFORM)\
		$(INTENSITY) $(SPATIAL_FILTER) $(FILTER_FREQ) \
		$(RESTORATION) $(COLORIMAGE) $(MORPH) $(MORPH_GRAY)

